﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.DataVisualization.Charting;

namespace Galaktika.BI.Silverlight.Intermediate.Charting
{
    public class AxisCollection : Collection<Axis>
    {
        public AxisCollection(Chart view):base()
        {
            this._view = view;
        }

        public AxisCollection(IList<Axis> axes, Chart view) : this(view)
        {
            foreach (var axe in axes)
            {
                this.Items.Add(axe);
            }
        }

        // Fields
        private Chart _view;

        // Methods
        protected override void ClearItems()
        {
            while (base.Count > 2)
            {
                this.RemoveItem(base.Count - 1);
            }
        }

        protected override void InsertItem(int index, Axis item)
        {
            base.InsertItem(index, item);
            this._view.Axes.Add(item);          
        }

        protected override void RemoveItem(int index)
        {
            if (index >= 2)
            {
                this._view.Axes.Remove(base[index]);
                base.RemoveItem(index);
            }
        }

        // Properties
        public Axis this[string name]
        {
            get
            {
                foreach (Axis axis in this)
                {
                    if (axis.Name == name)
                    {
                        return axis;
                    }
                }
                return null;
            }
        }

        internal Chart View
        {
            set
            {
                this._view = value;
            }
        }
    }


}
